import java.util.Arrays;

public class MyStack {
    int[] array;
    int size;

    public MyStack() {
        this.array = new int[10];
    }

    public void push(int val) {
        if (isFull(array)){
            dilatation();
        }
        array[size] = val;
        size++;
    }

    public boolean isFull(int[] array){
        return size == array.length;
    }

    public void dilatation(){
        array = Arrays.copyOf(array,array.length * 2);
    }

    public int pop() {
        int e = peck();
        size--;
        return e;
    }

    public int peck  (){
        if (empty()){
            throw new java.lang.RuntimeException("栈为空，无法获取栈顶元素");
        }
        return  array[size-1];
    }

    public int top() {
        return array[size-1];
    }

    public boolean empty(){
        return size == 0;
    }

    public int getMin() {
        int min = array[0];
        for(int i = 1;i < size ;i++){
            if(array[i] < min){
                min = array[i];
            }
        }return min;
    }
}
